import { _decorator, Component, Node, random } from 'cc';
const { ccclass, property } = _decorator;


class colorDate {
    color: string;
    id: number;

    public static new_bean(color: string, id: number) {
        let ret = new colorDate();
        ret.color = color;
        ret.id = id;
        return ret;
    }

    public clone(): colorDate {
        return colorDate.new_bean(this.color, this.id);
    }
}

@ccclass('DataModel')
export class DataModel {
    /** 电池所有的颜色 */
    public static base_color_arr = [
        // #c24242
        // #9142bb
        // #fff27d
        // #7fe589
        // #b9e71d
        // #4655e7
        // #dc4678
        // #a16ae4
        // #63e3eb
        // #faa96c
        // #f15d5d

        colorDate.new_bean("f15d5d", 10001),
        colorDate.new_bean("faa96c", 10002),
        colorDate.new_bean("fff27d", 10003),
        colorDate.new_bean("7fe589", 10004),
        colorDate.new_bean("b9e71d", 10005),
        colorDate.new_bean("63e3eb", 10006),
        colorDate.new_bean("4655e7", 10007),
        colorDate.new_bean("a16ae4", 10008),
        colorDate.new_bean("dc4678", 10009),
        colorDate.new_bean("9142bb", 10010),
    ];

    public static get_model_colorData(index:number){
        return DataModel.base_color_arr[index].clone()
    }

    /** 当前关卡电池颜色种类 */
    private static lvl_color_arr = [];
    public static generate_lvl_color_arr(args: number) {
        console.log('args:',args)
        DataModel.lvl_color_arr = [];
        for (let i = 0; i < DataModel.base_color_arr.length; i++) {
            DataModel.lvl_color_arr.push(DataModel.base_color_arr[i].clone());
            if (DataModel.lvl_color_arr.length >= args) {
                break;
            }
        }

        console.log(DataModel.base_color_arr.length, '数量：', DataModel.lvl_color_arr.length)
    }

    private static color_index: number = 0;
    /** 获取当前关卡一种电池的颜色 */
    public static get_lvl_color(): colorDate {
        if (DataModel.color_index >= DataModel.lvl_color_arr.length) {
            DataModel.color_index = 0;
        }
        let ret = DataModel.lvl_color_arr[DataModel.color_index];
        DataModel.color_index += 1;
        return ret;
    }

    private static layer_color_index: number = -1;
    /** 每一层的板子颜色，不随电池颜色变化 */
    public static get_layer_color(): colorDate {
        if(DataModel.layer_color_index == -1)DataModel.layer_color_index = Math.floor(Math.random() * DataModel.base_color_arr.length)
            
        let ret = DataModel.base_color_arr[DataModel.layer_color_index];
        DataModel.layer_color_index += 1;
        if (DataModel.layer_color_index >= DataModel.base_color_arr.length) {
            DataModel.layer_color_index = 0;
        }
        return ret;
    }

    /** 打乱颜色 */
    public static random_base_color() {
        DataModel.base_color_arr.sort(() => {
            return 0.5 - Math.random();
        });

    }



    // group_index_arr = [];
    private static cur_group_index = 0;

    public static get_new_group_index() {
        let temp = 1 << DataModel.cur_group_index;
        DataModel.cur_group_index += 1;
        if (DataModel.cur_group_index > 30) {
            DataModel.cur_group_index = 0;
        }
        // console.log("group:::::",temp);
        return temp;
    }
}
